package com.example.javaui.component;

import ohos.agp.components.AttrSet;
import ohos.agp.components.Component;
import ohos.agp.render.Canvas;
import ohos.agp.render.Paint;
import ohos.agp.utils.Color;
import ohos.agp.utils.TextAlignment;
import ohos.app.Context;

public class NeumorText extends Component implements Component.DrawTask {

    private Color color = Color.BLACK;
    private int textSize = 100;
    private String text = "";

    public NeumorText(Context context) {
        super(context);
        initView();
    }

    public NeumorText(Context context, AttrSet attrSet) {
        super(context, attrSet);
        initView();
    }

    public NeumorText(Context context, AttrSet attrSet, String styleName) {
        super(context, attrSet, styleName);
        initView();
    }

    public NeumorText(Context context, AttrSet attrSet, int resId) {
        super(context, attrSet, resId);
        initView();
    }

    private void initView() {
        this.addDrawTask(this);
    }

    @Override
    public void onDraw(Component component, Canvas canvas) {

        int width = getWidth();
        int height = getHeight();
        int shadowWidth = 40;
        int centerX = width / 2;
        int centerY = height / 2;
        int realWidth = width - shadowWidth * 2;
        int realHeight = height - shadowWidth * 2;

        Paint textPaint2 = new Paint();
        textPaint2.setTextSize(textSize);
        textPaint2.setColor(Color.LTGRAY);
        textPaint2.setTextAlign(TextAlignment.HORIZONTAL_CENTER);
        canvas.drawText(textPaint2, text, centerX + 3, centerY + textSize / 2 + 3);

        Paint textPaint = new Paint();
        textPaint.setTextSize(textSize);
        textPaint.setColor(color);
        textPaint.setTextAlign(TextAlignment.HORIZONTAL_CENTER);
        canvas.drawText(textPaint, text, centerX, centerY + textSize / 2);

    }

    public int getTextSize() {
        return textSize;
    }

    public void setTextSize(int textSize) {
        this.textSize = textSize;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public Color getColor() {
        return color;
    }

    public void setColor(Color color) {
        this.color = color;
    }
}
